package bo;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ad.AdDao;

/**
 * Servlet implementation class deltet
 */
@WebServlet("/delete")
public class delete extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public delete() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
        request.setCharacterEncoding("UTF-8");
        String id=request.getParameter("id");
        String username = request.getParameter("username");
		String userpwd = request.getParameter("userpwd");
		book b=new book();
		b.setId(id);
		b.setUsername(username);
		b.setUserpwd(userpwd);
		AdDao dao=new AdDao();
        book bb = new book();
        BookDao bkdao = new BookDao();
        try {
        	bb = dao.search(b);
        	bkdao.delete(bb);
        	request.setAttribute("b",b);
        	request.getRequestDispatcher("deletesuccess.jsp").forward(request, response);
        }catch(Exception e) {
        	e.printStackTrace();
        }
	}

}
